# 爬取在线书店http://books.toscrape.com/的所有信息，
# 包括图书的名字、封面图片、价格、评分、库存、产品介绍、所属分类。

import requests
from bs4 import BeautifulSoup

start_url = 'http://books.toscrape.com/'
next_page_url = start_url
r = requests.get(next_page_url)
bs = BeautifulSoup(r.text, 'html.parser')
# 下一图书列表页
# next_page = bs.find('li', class_='next')
# next_page_url = next_page.a['href']
# next_page_url = start_url + next_page_url
# print(next_page_url)

books_pages = bs.find_all('li', class_='col-xs-6 col-sm-4 col-md-3 col-lg-3')
for books_page in books_pages:
    books_page_url = books_page.a['href']
    books_page_url = start_url+books_page_url
    r = requests.get(books_page_url)
    bs = BeautifulSoup(r.text, 'html.parser')
    div_list = bs.find_all('div', class_='row')
    for div in div_list:
        print(div.h1)# 书名
        print(div.img)# 封面
        print(div.find('p',class_="price_color"))# 价格
        print(div.find('p',class_="instock availability"))# 库存
        print(div.find('p',class_="star-rating"))# 评分
    print(bs.find('table',class_="table table-striped"))# 介绍与分类
    print(books_page_url)# 二级图书页面链接














